/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.sapra.logon;

import echopointng.*;
import javax.servlet.http.HttpServletRequest;
import nextapp.echo2.app.Alignment;
import nextapp.echo2.app.ApplicationInstance;
import nextapp.echo2.app.Button;
import nextapp.echo2.app.Color;
import nextapp.echo2.app.Column;
import nextapp.echo2.app.Extent;
import nextapp.echo2.app.FillImage;
import nextapp.echo2.app.Font;
import nextapp.echo2.app.Grid;
import nextapp.echo2.app.ImageReference;
import nextapp.echo2.app.Label;
import nextapp.echo2.app.PasswordField;
import nextapp.echo2.app.Row;
import nextapp.echo2.app.ResourceImageReference;
import nextapp.echo2.app.TextField;
import nextapp.echo2.app.event.ActionEvent;
import nextapp.echo2.app.event.ActionListener;
import nextapp.echo2.webrender.WebRenderServlet;
import org.sapra.echo.Helpers;
import org.sapra.echo.Styles;
import org.sapra.echo.wAviso;
import org.sapra.main.vPrincipal;


/**
 * Generated Echo form template
 *
 * @author ppratsc
 */
public class wLogin extends nextapp.echo2.app.WindowPane {

   static String DIR_IMAGEN="org/sapra/echo/image/";
    static FillImage fondo;
    static Extent tamaño;
    static Font tipo;
    public wLogin() {
        super();
        this.setBackgroundImage(fondo=new FillImage(new ResourceImageReference(DIR_IMAGEN + "fondo.jpg")));
        this.setTitleBackgroundImage(new FillImage(new ResourceImageReference(DIR_IMAGEN+"fondo_titulo2.png")));
        this.setTitle("CAMARA DE LA INDUSTRIA DE LA TRANSFORMACION DE NUEVO LEON.");
        this.setTitleHeight(new Extent(33));
        this.setTitleFont(new Font(Font.ARIAL,1, new Extent(15)));
        this.setHeight(tamaño=new Extent(560));
        this.setWidth(tamaño=new Extent(705));
        this.setFont(tipo=new Font(new Font.Typeface("arial"),1,tamaño=new Extent(20)));

        //Propiedades de la VentanaasAS
        this.setClosable(false);
        this.setModal(true);
        this.setMovable(false);
        this.setResizable(false);

        add(new wLoginContentPane());
    }

    private class wLoginContentPane extends ContentPaneEx{

        TextField mUsr;
        PasswordField mPwd;

        public wLoginContentPane() {
           super();

            initComponents();
        }

        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {

            // Layout

            Column col1 = Helpers.Column("col1", new Extent(5), this);
            //col1.add(new Label(Styles.SAPRA_LOGO));
            Row rowlogo = Helpers.Row("row1", null, col1);
            rowlogo.add(new Label(Styles.SAPRA_LOGO));
            rowlogo.setAlignment(Alignment.ALIGN_CENTER);

            Row row1 = Helpers.Row("row1", null, col1);
            Row row2 = Helpers.Row("row2", null, col1);
            Row row3 = Helpers.Row("row3", null, col1);
            Row row4 = Helpers.Row("row4", null, col1);

            row1.setAlignment(Alignment.ALIGN_CENTER);
            row2.setAlignment(Alignment.ALIGN_CENTER);
            row3.setAlignment(Alignment.ALIGN_CENTER);
            row4.setAlignment(Alignment.ALIGN_CENTER);

            Grid ac=new Grid(2);

            boolean debug= false;
            //Label lTit= Helpers.Label("ZAPRAX 3.0",new Color(0x011dac),row1);
            Label lUsr= Helpers.Label("USUARIO:",new Color(0x011dac),ac);
            mUsr = Helpers.Text((debug)?"ppratsc":"",ac);
            Label lPwd= Helpers.Label("PASSWORD:",new Color(0x011dac),ac);
            mPwd = Helpers.Password((debug)?"Jw8aisrt":"",ac);

            HttpServletRequest sreq = WebRenderServlet.getActiveConnection().getRequest();
            String hostname = sreq.getServerName().toLowerCase();
            debug = hostname.equals("localhost");
            
            //mUsr = Helpers.Text((debug)?"ppratsc":"",ac);
            //mPwd = Helpers.Password((debug)?"Jw8aisrt":"",ac);

            row2.add(ac);

            Button  bOk = Helpers.Button("LOGIN",row4,new ActionListener(){public void actionPerformed(ActionEvent evt){ActionOK(evt);}});
            /*Button login =new Button();
            ImageReference rf3=new ResourceImageReference(dir3);
            login .setIcon(rf3);
            login .setToolTipText("Dar de alta un practicante.");
            //login.setStyleName("Default");
            //login.setWidth(new Extent(50));
            login.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                                ActionOK(e);
                    }
        });

        row4.add(login);*/

        }

        public void ActionOK(ActionEvent evt){

            if( !dLogin.Logon(mUsr.getText(), mPwd.getText()) ){
                add(new wAviso("SEGURIDAD","USUARIO O CONTRASEÑA INVALIDA"));
                return;
            }/*
            if(dLogin.getUser().getTipoUsuario().trim().toLowerCase().equals("a")){
                    //Inicia la Carga del Panel Principal
                    ApplicationInstance app = ApplicationInstance.getActive();
                    app.getDefaultWindow().setContent(new vPrincipal());

                    //Cierra Esta Ventana
                    wLogin win = (wLogin)getParent();
                    win.userClose();
            }else{
                 add(new wAviso("SEGURIDAD","HASTA EL MOMENTO SOLO DISPONIBLE PARA ADMINISTRADORES"));
                return;
            }*/
                ApplicationInstance app = ApplicationInstance.getActive();
                    app.getDefaultWindow().setContent(new vPrincipal());

                    //Cierra Esta Ventana
                    wLogin win = (wLogin)getParent();
                    win.userClose();
        }
 // Action listeners


        // Variables declaration - do not modify

    }
}
